#ifndef GUI_ELEMENT_H
#define GUI_ELEMENT_H

#include "../UniversalIncludes.h"
#include "../SceneObject.h"
#include "../DrawHelper.h"

// Different gui element state classifications that can be represented
// The Hover state is synonymous for a Focus state for keyboard/controller.
enum ElementState
{
    Normal = 0,
    Hover = 1,
    Active = 2
};

/*
 * This class serves as the basic inherited class for all gui "elements."
 *
 * It is complex in that it has to deal with two different forms of
 * input interactions: mouse/pointer interaction, and keyboard/controller
 * interaction. In particular, the use of isPressed is necessary to streamline
 * the utility of the mouse/pointer. (So if a user clicks and holds on an
 * element and drags the mouse away it will still appear pressed until the user
 * "unclicks.")
 *
 * Basic mouse events are handled by this class since pointer interaction
 * is universal. The binding of keyboard/controller input is done exterior
 * to this class.
 */

class GUIElement : public SceneObject
{
    // Fields
    public:
        Color* bgColor[3];                              // Background colors for each state
        Color* borderColor[3];                          // Border colors for each state
        Color* textColor[3];                            // Text colors for each state
        ElementState state;
        int width;
        int height;
        int borderSize;
        int padding;                                    // Padding between the edges of the element and the insde (e.g. the text)
        int fontSize;
        std::string text;
    protected:
        bool isPressed;                                 // If element state is Active
    private:
        bool isHovered;                                 // Save hovered state so we don't have to check again.
                                                        // Shouldn't need to be used outside GUIElement; it does not add any extra
                                                        // functionality other than allowing us to update the element's state.
    // Methods
    public:
        GUIElement();
        virtual ~GUIElement()
        {
            delete bgColor;
            delete borderColor;
            delete textColor;
        }
        void handleEvents(SDL_Event* event);
        void setState(ElementState elemState);
        virtual void onPressed(){}                      // Used externally when user activates this element
        virtual void onReleased(){}                     // Used externally when user ceases activation of this element
    protected:
        virtual void onPressed(Uint8 mouseState){}      // Fired automatically when user clicks on this element
        virtual void onReleased(Uint8 mouseState){}     // Fired automatically when the user releases the mouse button on this element
};

#endif
